import request from '@/utils/request'
import type { User, UserQuery } from '@/types/api/user'

// 获取用户列表
export function getUserList(params: UserQuery) {
  return request<User[]>({
    url: '/user/list',
    method: 'get',
    params
  })
}

// 添加用户
export function addUser(data: Partial<User>) {
  return request({
    url: '/user',
    method: 'post',
    data
  })
}

// 更新用户
export function updateUser(data: Partial<User>) {
  return request({
    url: `/user/${data.id}`,
    method: 'put',
    data
  })
}

// 删除用户
export function deleteUser(id: number) {
  return request({
    url: `/user/${id}`,
    method: 'delete'
  })
}

// 获取用户角色
export function getUserRoles(userId: number) {
  return request<number[]>({
    url: `/user/${userId}/roles`,
    method: 'get'
  })
}

// 保存用户角色
export function saveUserRoles(data: { userId: number; roleIds: number[] }) {
  return request({
    url: `/user/${data.userId}/roles`,
    method: 'put',
    data
  })
} 